﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestCase_2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Timezone:{0}\n",TimeZoneInfo.Local.ToString());
            DateTime cdt = DateTime.Now;
            Console.WriteLine("Current Date Time: {0}\n",cdt.ToString());
            Console.WriteLine("Current Date Time to UTC time: {0}\n", NowToUTC(cdt).ToString());
            Console.WriteLine("UTC Time: {0} \n",UTCTime().ToString());
            Console.WriteLine("UTC to Server Time: {0} \n", UTCToServerTime(UTCTime()).ToString());
            Console.WriteLine("Formated Date and Time: {0}\n",DateTimeToString());
            Console.WriteLine("Formated Date and Time with Culture: {0}\n",DateTimeWithCulture());
            Console.WriteLine("UTC Time to Local Time: {0}\n",UTCToLocalTime().ToString());
            Console.WriteLine("Format UTC Time: {0}\n",UTCFormatted().ToString());
            string daa = DateTimeToString();
            DateTime aftcon = Convert.ToDateTime(daa);
            Console.WriteLine("Result: {0}",aftcon);
            Console.ReadKey();
        }
        private static string UTCFormatted()
        {

            DateTime dt = DateTime.Now;
            return dt.ToString("yyyy-MM-ddTHH:mm:ss.fff"); 
           
        }

        private static DateTime UTCToLocalTime()
        {
            DateTime dt = DateTime.UtcNow;
            TimeZoneInfo.ConvertTimeFromUtc(dt, TimeZoneInfo.Local);
            return dt;

        }

        private static string DateTimeWithCulture()
        {
            string date = "01/08/2012";
            DateTime dt = Convert.ToDateTime(date);
            IFormatProvider culture = new System.Globalization.CultureInfo("vi-VN", true);
            DateTime dt2 = DateTime.Parse(date, culture, System.Globalization.DateTimeStyles.AssumeLocal);
            string rs=dt2.ToString();
            return rs;
        }

        private static string DateTimeToString()
        {
            DateTime dt = DateTime.Now;
            string format = "dd-MM-yyyy HH:mm:ss.ff";
            return dt.ToString(format);
        }

        private static DateTime UTCTime()
        {
            DateTime dt = DateTime.UtcNow;
            return dt;
        }

        private static DateTime UTCToServerTime(DateTime inputDateTime)
        {
            inputDateTime = DateTime.UtcNow.ToLocalTime();
            return inputDateTime;
        }
        private static DateTime NowToUTC(DateTime input)
        {
            input = DateTime.UtcNow.ToUniversalTime();
            return input;
        }
    }
}
